package com.lycos.ludrien.client;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.HashMap;

public class LiaisonMotSimple {

	
	private class Donnee{
		public int nbOccur;
		public Boolean isTitle;
		public int frequence;
		public Donnee(int p_nbOccur, int p_frequence){
			this.nbOccur = p_nbOccur;
			this.frequence = p_frequence;
			this.isTitle = false;
		}
	}
	
	public int idMot;
	private HashMap<Integer, Donnee> idPara_Donne;
	
	public LiaisonMotSimple(int p_idMot, Connection con){
		ResultSet rs ;
		int id = 0;
		this.idMot = p_idMot;
		idPara_Donne = new HashMap<Integer, LiaisonMotSimple.Donnee>();
		try {


			String req = "Select ID_paragraphe, nb_occu, frequence from liaison_mp_calc where ID_motcle = "+ idMot ;
			PreparedStatement pstmt = con.prepareStatement(req);
			rs = pstmt.executeQuery();

			while (rs.next()){
				Donnee d = new Donnee(rs.getInt(2), rs.getInt(3));
				idPara_Donne.put(rs.getInt(1), d);}
			
			req = "Select distinct ID_paragraphe from liaison_mp where provenance != 'content' and ID_motcle = "+ idMot ;
			pstmt = con.prepareStatement(req);
			rs = pstmt.executeQuery();

	
			while (rs.next()){
				id = rs.getInt(1);
				//System.out.println(id);
				Donnee d = idPara_Donne.get(rs.getInt(1));
				//System.out.println(id + "-" + this.idMot );
				d.isTitle = true;
				idPara_Donne.put(rs.getInt(1), d);}
		
		}catch (Exception e){
			System.out.println(id + "-" + this.idMot );
			System.out.println(e);
			}

		
	}
	
	public int getNbOccur(int idPara){
		int nbOccur = 0;
		if (idPara_Donne.containsKey(idPara)) nbOccur = idPara_Donne.get(idPara).nbOccur;
		return nbOccur;
	}
	public int getFreq(int idPara){
		int freq = 0;
		if (idPara_Donne.containsKey(idPara)) freq = idPara_Donne.get(idPara).frequence;
		return freq;
	}
	public Boolean getIsTitle(int idPara){
		Boolean isTitle = false;
		if (idPara_Donne.containsKey(idPara)) isTitle = idPara_Donne.get(idPara).isTitle;
		return isTitle;
	}
}
